Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ioredis

Package Overview
Dependencies
Maintainers
2
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ioredis

A robust, performance-focused and full-featured Redis client for Node.js.

  • 4.28.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4M
increased by8.9%
Maintainers
2
Weekly downloads
 
Created

What is ioredis?

ioredis is a robust, performance-focused, and full-featured Redis client for Node.js. It supports both Redis commands and the cluster mode introduced in Redis 3.0. It provides a more intuitive and flexible way to interact with a Redis server or a cluster of Redis servers, offering features like automatic reconnection, offline queueing, and support for transactions, pub/sub, and Lua scripting.

What are ioredis's main functionalities?

Basic Commands

Execute basic Redis commands such as SET and GET. This example demonstrates setting and getting the value of a key.

const Redis = require('ioredis');
const redis = new Redis();
redis.set('foo', 'bar');
redis.get('foo', (err, result) => {
  console.log(result);
});

Publish/Subscribe

Use Redis' pub/sub capabilities to publish messages to a channel and subscribe to receive messages from that channel.

const Redis = require('ioredis');
const subscriber = new Redis();
const publisher = new Redis();
subscriber.subscribe('news', () => {
  publisher.publish('news', 'Hello world!');
});
subscriber.on('message', (channel, message) => {
  console.log(`Received \
${message} from ${channel}`);
});

Transactions

Perform transactions using the MULTI/EXEC commands to execute multiple commands atomically.

const Redis = require('ioredis');
const redis = new Redis();
redis.multi()
  .set('foo', 'bar')
  .get('foo')
  .exec((err, results) => {
    console.log(results);
  });

Pipeline

Use pipelining to send multiple commands to the server without waiting for the replies, improving performance.

const Redis = require('ioredis');
const redis = new Redis();
redis.pipeline()
  .set('foo', 'bar')
  .get('foo')
  .del('foo')
  .exec((err, results) => {
    console.log(results);
  });

Lua Scripting

Extend Redis with Lua scripting. This example defines a custom command that gets the current value of a key and sets it to a new value atomically.

const Redis = require('ioredis');
const redis = new Redis();
redis.defineCommand('getAndSet', {
  numberOfKeys: 1,
  lua: 'return {redis.call('get', KEYS[1]), redis.call('set', KEYS[1], ARGV[1])}'
});
redis.getAndSet('foo', 'new value', (err, result) => {
  console.log(result);
});

Other packages similar to ioredis

Keywords

FAQs

Package last updated on 06 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc